<include file="Public/header" />


<div class="col-sm-offset-2 col-xs-8" style="margin-top: 50px;">
	<div class="content">
		<h1 class="text-center" id='title'>
			我的站点
		</h1>
		<h3 class="text-center"><small><span id='typename'>今天天气不错</span>&nbsp;&nbsp;•&nbsp;&nbsp;<span id='author'>今天天气不错</span>&nbsp;&nbsp;•&nbsp;&nbsp;<span id="createtime">2014.1.1 15:29</span></small></h3>
		<p id='content'>
		</p>
	<p>
		阅读&nbsp;&nbsp;
		<span id="read_num">0</span>
		&nbsp;&nbsp;
		<span id='good'></span>
		&nbsp;&nbsp;
		<span id="good_num">0</span>
	</p>

	</div>
    <div id='say' style="margin-top: 30px;">
        <h3>发表评论</h3>

        <div class="input-group">
            <textarea id="user_comment" maxlength="100" class="form-control inputarea" placeholder="说点什么吧"></textarea>
        </div>

        <button type="button" onclick="comment()" class="btn btn-primary">发表评论</button>
    </div>
</div>

<div class="col-sm-offset-2 col-xs-8" style="float:left">
    <h3 class="text-center">
        评论&nbsp;&nbsp;(<span id="comment_num">0</span>)
    </h3>
    <div class="border">&nbsp;</div>
    <div id="comment">
	</div>
</div>


<script src="__ROOT__/Public/js/jquery.min.js"></script>
<script src="__ROOT__/Public/js/bootstrap.min.js"></script>

<include file="Public/footer_article_list" />
<script>
	$(function(){
		var client = new HproseHttpClient('__PATHHPROSE__/hprose.php/Article', ['getArticleDetail']);
		client.getArticleDetail("{$aid}",function(result){
			result = JSON.parse(result);
			console.log(result);
			if(result.success == 1){
				$('#title').html(result.article.title);
				$('#typename').html(result.article.typename);
				$('#author').html(result.article.author);
				$('#content').html('<table>'+result.article.content+'></table>');

				$('#good_num').html(result.article.good_num);
				if(result.article.good == 0){
					$("#good").html('<a style="cursor:pointer" onclick="goodArticle()"><span class="glyphicon glyphicon-thumbs-up"></span></a>');
				}
				else{
					$("#good").html('<span class="glyphicon glyphicon-thumbs-up"></span>');
				}
				$('#read_num').html(result.article.read_num);
				$('#comment_num').html(result.comment_num);
				$('#createtime').html(result.article.createtime);
				var p='';
				$.each(result.comment,function(i,item){
					p +='<img style="width:30px;height:30px" src="'+item.photo+'">';
					p +='<span>'+item.name+'</span>&nbsp;&nbsp;<span>'+item.createtime+'</span>';
					p +='<p class="popover-content">'+item.content+'</p>';
					if(item.good == 0){
						p +='<span id="comment'+item.id+'"><a style="cursor:pointer" onclick="goodComment('+item.id+')"><span class="glyphicon glyphicon-thumbs-up"></span></a></span>';
					}
					else{
						p +='<span class="glyphicon glyphicon-thumbs-up"></span>';
					}
					p +='&nbsp;&nbsp;<span id="comment-good_num'+item.id+'">'+item.good_num+'</span>';
					p +='<div class="border">&nbsp;</div>';
				});
				$("#comment").html(p);
			}
		})
	})
	function comment(){
		var content = $('#user_comment').val();
		var client = new HproseHttpClient('__PATHHPROSE__/hprose.php/Article', ['comment']);
		client.comment(content,"{$aid}",function(result){
			result = JSON.parse(result);
			if(result.success == 1){
				alert('success!');
				location.reload();
			}
			else{
				alert(result.info);
			}
		})
	}
	// alert("{$aid}");
	function goodArticle(){
		var client = new HproseHttpClient('__PATHHPROSE__/hprose.php/Article', ['setGoodArticle']);
		client.setGoodArticle("{$aid}",function(result){
			result = JSON.parse(result);
			console.log(result);
			if(result.success == 1){
				$("#good").html('<span class="glyphicon glyphicon-thumbs-up"></span>');
				$("#good_num").html(result.good_num);
			}
			else{
				alert(result.info);
			}
		})
	}
	function goodComment(cid){

		var client = new HproseHttpClient('__PATHHPROSE__/hprose.php/Article', ['setGoodComment']);
		client.setGoodComment(cid,function(result){
			result = JSON.parse(result);
			console.log(result);
			if(result.success == 1){
				$("#comment"+result.id).html('<span class="glyphicon glyphicon-thumbs-up"></span>');
				$("#comment-good_num"+result.id).html(result.good_num);
			}
			else{
				alert(result.info);
			}
		})
	}
</script>